<?php
class CBadge extends Zend_Db_Table
{
	protected $_name;
	protected $_primary;

	public function __construct()
	{
		$this->_name = R_PRE."badge";
		$this->_primary = "badge_id";
		parent::__construct();
		
	}
	
	public function getItemBadge($itemid)
	{
		$select = $this->getAdapter()->select();
		$select->from(array('a'=>$this->_name), '*')
			   ->joinInner(array('s'=>'zcshop_badge_product'), 'a.badge_id=s.badge_id')
			   ->where('s.itemid = ?', $itemid);
		return $this->getAdapter()->fetchAll($select);
	}
	
	public function getbadgebuyid($id = 1)
	{
		$db=$this->getAdapter();
		$select = $db->select();
		$select->from($this->_name,'*');
		$select->where('badge_id=? ',$id);
		$returndata = $db->fetchRow($select);
		return $returndata;
	}
	
	public function geteditbadge($data)
	{
		if(is_array($data) && !empty($data['badges'])) {
			$data['badges'] = unserialize($data['badges']);
			if(is_array($data['badges'])) {
				$temp_str = '';
				foreach ($data['badges'] as $badges) {
					if($badges == '')
						continue;
					$temp_str .= "$badges\n";
				}
				$data['badges'] = $temp_str;
			}
		}
		return $data;
	}
	
	public function add($str = '')
	{
	}

}